package com.example.mybatis.service.impl;

import com.example.mybatis.model.User;
import com.example.mybatis.service.IRedisService;
import com.example.mybatis.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.redis.core.RedisTemplate;
import org.thymeleaf.util.StringUtils;
import redis.clients.jedis.Jedis;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.HashMap;

import java.util.UUID;

@Service("redisService")
public class RedisService implements IRedisService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public User getUser(String uuid) {

       return (User) redisTemplate.opsForValue().get(uuid);

    }

    @Override
    public String saveUserInfo(User user) {
        if(StringUtils.isEmpty(user.getUuid())){
            String uuid = UUID.randomUUID().toString().replace("-","");
            user.setUuid(uuid);
        }

        redisTemplate.opsForValue().set(user.getUuid(),user);
        return user.getUuid();
    }
}
